<title>Using Batch support in Google Base</title>
<h1>The batch support</h1>

<p>Release 1.0.5 includes support for the GoogleBatch protocol extensions. Refer to 
the code.google.com documentation for details on this in general. </p>
<p>
In the C# libraries this is implemented as basic support on the AtomFeed and AtomEntry.
Those objects have a new member, called BatchData. Setting this data controls the 
operations executed on the batchfeed, and this object also holds the return values 
for from the server. </p>

<p>
To create a feed useful to talk to the batch service, you need to know the service URI 
for this. Here is a code snippet that retrieves that URI.</p>

<code>
    FeedQuery query = new FeedQuery();<br>
    Service service = new Service("gbase", "mytestapplication"); <br>
    NetworkCredential nc = new NetworkCredential(userName, passWord); <br>
    service.Credentials = nc;<br>

    // setup the google web key<br>
    GDataGAuthRequestFactory authFactory = service.RequestFactor as GDataGAuthRequestFactory; <br>
    authFactory.GoogleWebKey = "yourkey"; <br>

    query.Uri = new Uri("http://base.google.com/base/feeds/items");<br>
    AtomFeed baseFeed = service.Query(query);<br>

    // this should have a batch URI <br>
    if (baseFeed.Batch != null)  {<br>
    .... 
</code>

<p>
Note, that to talk to GoogleBase, you also need a web developer key, you can see above
that, once you have that key, you only need to set the GoogleWebKey property on the service
to use it. 
<p>
Now to set the default operation you want the batchfeed to do, you use code similiar to this:</p>

<code>
   <br> batchFeed.BatchData = new GDataBatchFeedData();
   <br> batchFeed.BatchData.Type = GDataBatchOperationType.delete; 
</code>

<p>If you do not set this, the feed will default to insert as it's operation type.

<p>You would then go and add entries to your feed. If you want the entry to behave differently
than the feed itself, you set the BatchData object on the entry. </p>

<code>
   <br> entry.BatchData = new GDataBatchEntryData();
   <br> entry.BatchData.Type = GDataBatchOperationType.insert; 
   <br> entry.BatchData.Id = "some id"; 
</code>
<p>
To finally do the batch, you just call the new service method for this purpose:
</p>
<code>
    <br>AtomFeed resultFeed = service.Batch(batchFeed, new Uri(baseFeed.Batch));
</code>
<p>
To verify that the operations were successfull, you need to iterate over the returned entries:
</p>
<code>
<br>        foreach (AtomEntry resultEntry in resultFeed.Entries )
    <br>    {
    <br>       GDataBatchEntryData data = resultEntry.BatchData;
    <br>        switch (data.Stutus.Code) {
    <br>           case 200:....
    <br>        }
<br>        }
</code>
